From: robertl Date: Tue, 17 Aug 2010 02:36:27 +0000 (+0000) Subject: Allow alt to be optional an KML reads. X-Git-Tag: archive/raspbian/1.10.0+ds-2+rpi1~1^2~12^2~16^2~22 X-Git-Url: https://dgit.raspbian.org/%22http://www.example.com/cgi/%22/%22http:/www.example.com/cgi/%22?a=commitdiff_plain;h=b3841d3c9590ef6ce518289ac0e2d0ec2992ebc1;p=gpsbabel.git Allow alt to be optional an KML reads. --- diff --git a/kml.c b/kml.c index 4ddc63174..479836f16 100644 --- a/kml.c +++ b/kml.c @@ -239,7 +239,17 @@ void wpt_time(const char *args, const char **unused) void wpt_coord(const char *args, const char **attrv) { - sscanf(args, "%lf,%lf,%lf", &wpt_tmp->longitude, &wpt_tmp->latitude, &wpt_tmp->altitude); + int n = 0; + double lat, lon, alt; + // Alt is actually optional. + n = sscanf(args, "%lf,%lf,%lf", &lat, &lon, &alt); + if (n > 2) { + wpt_tmp->latitude = lat; + wpt_tmp->longitude = lon; + } + if (n == 3) { + wpt_tmp->altitude = alt; + } wpt_tmp_queued = 1; } @@ -256,6 +266,7 @@ void trk_coord(const char *args, const char **attrv) int consumed = 0; double lat, lon, alt; waypoint *trkpt; + int n = 0; route_head *trk_head = route_head_alloc(); if (wpt_tmp->shortname) { @@ -263,11 +274,20 @@ void trk_coord(const char *args, const char **attrv) } track_add_head(trk_head); - while (3 == sscanf(args, "%lf,%lf,%lf %n", &lon, &lat, &alt, &consumed)){ + while ((n = sscanf(args, "%lf,%lf,%lf %n", &lon, &lat, &alt, &consumed)) > 0) { + trkpt = waypt_new(); trkpt->latitude = lat; trkpt->longitude = lon; - trkpt->altitude = alt; + + // Line malformed or two-arg format without alt . Rescan. + if (2 == n) { + sscanf(args, "%lf,%lf %n", &lon, &lat, &consumed); + } + + if (3 == n) { + trkpt->altitude = alt; + } track_add_wpt(trk_head, trkpt);